package utilities 
{
	import cgs.server.abtesting.messages.ConditionVariableMessage;
	import enemies.Enemy;
	import org.flixel.FlxBasic;
	import org.flixel.FlxG;
	import org.flixel.FlxGroup;
	import org.flixel.FlxObject;
	import org.flixel.FlxTimer;
	import org.flixel.plugin.photonstorm.FlxDelay;
	
	/**
	 * ...
	 * @author Andrew Lau
	 */
	public class Wave extends FlxObject
	{
		protected var _delay:FlxDelay;
		protected var _ended:Boolean;
		protected var _entities:Array;
		protected var _time:Number;
		protected var _timeEnd:Boolean;
		protected var _warning:Boolean;
		
		public function Wave() 
		{
			_delay = new FlxDelay(0);
			_delay.callback = timerEnded;
			
			_ended = false;
			
			_entities = new Array();
			
			_time = 0;
			
			_timeEnd = false;
			
			_warning = false;
		}
		
		public function set delay(millis:Number):void
		{
			_time = millis;
		}
		
		public function get delay():Number
		{
			return _delay.duration;
		}
		
		public function get ended():Boolean
		{
			return _ended;
		}
		
		override public function update():void
		{
			super.update();
			
			var ended:Boolean = true;
			
			for (var i:uint = 0; i < _entities.length; i++)
			{
				var t:Entity = _entities[i];
				if(t is Enemy) {
					ended = ended && !(t.exists);
				}
			}
			
			if (ended && !_delay.isRunning) {
				_ended = true;
				_delay.reset(_time);
			}
		}
		
		public function addEntity(e:Entity):void
		{
			_entities.push(e);
		}
		
		public function get entities():Array
		{
			return _entities;
		}
		
		public function get timerFinished():Boolean
		{
			return _timeEnd;
		}
		
		public function playWarning():void
		{
			if (!_warning) {
				_warning = true;
				Animation.intruderWarning();
			}
		}
		
		protected function timerEnded():void
		{
			_timeEnd = true;
		}
		
		/*public function addEntity(e:Entity):void
		{
			var temp:Array = new Array;
			
			if (e is Item)
			{
				temp.push(Registry.items.add);
			}
			else if (e is Interaction)
			{
				temp.push(Registry.interactions.add);
			}
			else if (e is Enemy)
			{
				temp.push(Registry.enemies.add);
			}
			else if (e is Treasure)
			{
				temp.push(Registry.treasures.add);
			}
			else if (e is Decoration)
			{
				temp.push(Registry.decorations.add);
			}
			
			temp.push(e);
		}*/
		
	}

}